package com.example.networkrequestencapsulation.base;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import butterknife.ButterKnife;
import com.example.networkrequestencapsulation.AppManager;
import com.gyf.immersionbar.ImmersionBar;

/**
 * 作者 : chenyixi
 * 日期 : 2019/11/19 18:20
 * 文件包名 : com.example.networkrequestencapsulation.base
 * 描述 :
 */
public abstract class BaseActivity extends AppCompatActivity {

    protected String TAG = "";
    protected Activity mActivity;
    protected Context mContext;

    protected abstract int getLayoutId();//获取布局id

    protected abstract void initData();// 初始化数据

    protected abstract void initListener();// 初始化监听器

    /**
     * 初始化沉浸式
     * Init immersion bar.
     */
    protected void initImmersionBar() {
        //设置共同沉浸式样式
        ImmersionBar.with(this).init();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        TAG = this.getClass().getSimpleName();
        mActivity = this;
        mContext = this;

        initData();
        initListener();
        initImmersionBar();


        AppManager.getAppManager().addActivity(this);

    }


    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AppManager.getAppManager().removeActivity(this);
    }
}
